package ru.papergames.web.blines.battle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import ru.papergames.common.beans.BattleMember;
import ru.papergames.common.form.BattleServerCredentialsForm;
import ru.papergames.web.blines.battle.model.BattleOrder2;

import java.util.List;

/**
 * @author: atroshanin
 * Date: 14.09.2010
 * Time: 21:31:10
 */
public class BattleLifeCycleListenerImpl implements BattleLifeCycleListener {

    private static Log log = LogFactory.getLog(BattleLifeCycleListenerImpl.class);

    private BattleOrder2 battleOrder;

    public BattleLifeCycleListenerImpl(BattleOrder2 battleOrder) {
        this.battleOrder = battleOrder;
    }

    public void onBattleCreateOk(int battleOrderId, BattleServerCredentialsForm serverCredentials) {
        log.info("new battle created: " + battleOrderId);
//        battleOrder.setBattleId(battleOrderId);
//        battleOrder.setBattleServerCredentials(serverCredentials);
        //MessagingServersManager.getInstance().notifyBattleOrderMembersAboutBattleStart(battleOrder, serverCredentials);
    }

    public void onBattleCreateFail() {
        BattleOrdersHolder2.getInstance().removeBattleOrder(battleOrder);
        log.info("Failed to create battle for order:" + battleOrder.getId());
    }

    public void onBattleFinish(int winnerTeamId, List<BattleMember> battleMembers) {
        BattleOrdersHolder2.getInstance().removeBattleOrder(battleOrder);
        log.info("Battle[" + battleOrder.getId() + "] finished");
    }

    public void onBattleStart() {
        log.info("Battle[" + battleOrder.getId() + "] started");
    }
}
